package ar.edu.unlp.info.tesis.database.operator;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Expression;

public abstract class OperatorRestriction {

	public OperatorRestriction() {
		super();
	}

	public OperatorRestriction(String field) {
		this.field = field;
	}

	public OperatorRestriction(String field, Object value) {
		this.field = field;
		this.value = value;
	}

	private String field;

	private Object value;

	// si es una expresion negativa
	private boolean isNegativeOperator = false;

	/**
	 * @return Returns the field.
	 */
	public String getField() {
		return field;
	}

	/**
	 * @param field
	 *            The field to set.
	 */
	public void setField(String field) {
		this.field = field;
	}

	/**
	 * @return Returns the value.
	 */
	public Object getValue() {
		return value;
	}

	/**
	 * @param value
	 *            The value to set.
	 */
	public void setValue(Object value) {
		this.value = value;
	}

	public Criterion getCriteriaExpresion() {
		Criterion cri = this.getExpresion();
		if (this.isNegativeOperator) {
			cri = Expression.not(cri);
		}
		return cri;
	}

	public abstract Criterion getExpresion();

	public boolean isNegativeOperator() {
		return isNegativeOperator;
	}

	public void setNegativeOperator(boolean isNegativeOperator) {
		this.isNegativeOperator = isNegativeOperator;
	}
}
